package com.tom.architect.party5.day37.simple5.base;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

/**
 * Added by Tom on 2024/09/30.
 * MVP Activity 基类
 */
public abstract class BaseMvpActivity<P extends BasePresenter>
        extends AppCompatActivity
        implements BaseView {
    private P mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView();

        // 创建P，创建交给子类，每个Activity不一样。
        mPresenter = createPresenter();
        mPresenter.attach(this);

        initView();
        initData();
    }

    // 子类自己实现 P的创建
    protected abstract P createPresenter();

    protected abstract void initData();

    protected abstract void initView();

    protected abstract void setContentView();

    @Override
    public void onDestroy() {
        super.onDestroy();
        mPresenter.detach();
    }

    public P getPresenter() {
        return mPresenter;
    }
}
